<template>
	<view>
		<view class="top">
			<view class="search">
				<u-search height="100" :animation="true" placeholder="搜索您想要的商品" v-model="keyword"></u-search>
			</view>
			<image class="car" @click="toPage('car')" src="../static/a2.png"></image>
		</view>
		<view class="banner">
			<u-swiper :list="swiper"  @click="getSwiper" height="291" imgMode="scaleToFill" mode="dot"
				indicator-pos="bottomRight">
			</u-swiper>
		</view>
		<view class="classify">
			<view class="list" :style="'background:'+item.color+';'" @click="scrollTo(item.cid,index)"
				:class="active==index?'active':''" v-for="(item,index) in cateList" :key="index">
				<image :src="img_pre+item.icon" mode=""></image>
				<view class="name">
					{{item.cname}}
				</view>
			</view>
		</view>
		<view class="content">
			<view class="list" :class="'tab_item'+item.cid" v-for="(item,index) in cateProductList" :key="index">
				<view class="title">
					<view class="name omit">
						{{item.cname}}
					</view>
					<view class="text" @click="toPage('classify?cid='+item.cid)">
						查看全部
					</view>
				</view>
				<view class="down">
					<view class="goods" @click="toPage('details?pid='+a.pid)" v-for="(a,b) in item.productlist"
						:key="b">
						<u-lazy-load height="421" imgMode="scaleToFill" :borderRadius="20" :image="img_pre+a.thumbnail">
						</u-lazy-load>
						<view class="name">
							{{a.pname}}
						</view>
						<view class="text">
							{{a.price}} <text>蜂钻</text>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	var than;
	export default {
		data() {
			return {
				keyword: "",
				active: 0,
				pageTop: 0,
				swiper: [],
				cateList: [],
				cateProductList: []
			}
		},
		onLoad(option) {
			than = this;
			than.getCateList();
			than.getCateProductList();
			than.post("api/Product/lunboList", null, function(data) {
				for (let i in data) {
					var json = {
						image: than.img_pre + data[i].picture,
						pid: data[i].pid
					}
					than.swiper.push(json)
				}
			})
		},
		methods: {
			getSwiper(e){
				than.toPage('details?pid='+than.swiper[e].pid)
			},
			getCateList() {
				than.post('api/Product/cateList', null, function(data) {
					than.cateList = data;
				})
			},
			getCateProductList() {
				than.post('api/Product/cateProductList', null, function(data) {
					than.cateProductList = data;
				})
			},
			scrollTo(cid, index) {
				than.active = index;
				let view = uni.createSelectorQuery().in(than).select(".tab_item" + cid);
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 0,
					success: function() {
						view.boundingClientRect(data => {
							uni.pageScrollTo({
								scrollTop: data.top + than.pageTop,
								duration: 300
							})
						}).exec();
					}
				})
			}
		}
	}
</script>

<style lang="less">
	.top {
		display: flex;
		align-items: center;
		padding: 0 36rpx;

		.search {
			width: 554rpx;
			background: #F6F6F8;
			height: 100rpx;
			border-radius: 22rpx;
		}

		.car {
			margin-left: auto;
			width: 100rpx;
			height: 100rpx;
		}
	}

	.banner {
		width: 678rpx;
		height: 291rpx;
		margin: 20rpx auto;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.classify {
		display: flex;
		align-items: center;
		padding-left: 36rpx;
		overflow: scroll;
		white-space: nowrap;
		margin-top: 10rpx;

		.active {
			background: linear-gradient(0deg, #FFD03F, #FFC102) !important;
			color: #333333 !important;
		}

		.list {
			flex-shrink: 0;
			border-radius: 70rpx;
			margin-right: 24rpx;
			text-align: center;
			height: 205rpx;
			width: 140rpx;
			padding-top: 15rpx;
			color: #FFFFFF;

			image {
				width: 110rpx;
				height: 110rpx;
				border-radius: 50%;
			}
		}
	}

	.content {


		.list {

			.title {
				padding: 0 37rpx;
				display: flex;
				align-items: center;
				height: 105rpx;

				.text {
					margin-left: auto;
					font-size: 26rpx;
					font-family: PingFang SC;
					font-weight: bold;
					color: #333333;
				}

				.name {
					font-size: 36rpx;
					font-family: PingFang SC;
					font-weight: bold;
					color: #39383D;
				}
			}

			.down {
				overflow: scroll;
				display: flex;
				white-space: nowrap;
				padding-left: 37rpx;

				.goods {
					flex-shrink: 0;
					margin-right: 24rpx;
					margin-bottom: 30rpx;
					width: 315rpx;

					.name {
						overflow: hidden;
						margin-top: 10rpx;
						font-size: 28rpx;
						font-family: PingFang SC;
						font-weight: bold;
						color: #001111;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
					}

					.text {
						margin-top: 10rpx;
						font-size: 28rpx;
						font-family: PingFang SC;
						font-weight: bold;
						color: #333333;

						text {
							font-size: 24rpx;
							font-family: PingFang SC;
							font-weight: bold;
							color: #333333;
						}
					}
				}
			}
		}
	}
</style>
